from itsdangerous import TimedJSONWebSignatureSerializer as Serializer,BadTimeSignature,SignatureExpired
from meiduo_mall import settings

def generic_email_access_token(user_id,email):
    s = Serializer(settings.SECRET_KEY, expires_in=3600)
    # 加密
    token = s.dumps({
        'id': user_id,
        'email': email
    })
    access_token = token.decode()

    return access_token

def check_email_token(token):

    #穿件serialzier实例，解密，获取数据
    s = Serializer(settings.SECRET_KEY, expires_in=3600)

    try:
        result=s.loads(token)

    except Exception:
        return None
    return result





